1
|
|
|
var chai = require('chai'); |
2
|
|
|
var path = require('path'); |
3
|
|
|
|
4
|
|
|
var Manager = require('../src/cli').Manager |
5
|
|
|
var config = require('../src/cli').config |
6
|
|
|
var cmsOperations = require('../src/cli').cmsOperations |
7
|
|
|
config.set({root: __dirname + '/fixtures/'}) |
|
|
|
|
8
|
|
|
|
9
|
|
|
var cmsData = require('../src/cli').cmsData; |
10
|
|
|
var Manager = require('../src/cli').Manager; |
|
|
|
|
11
|
|
|
var fse = require('fs-extra'); |
12
|
|
|
|
13
|
|
|
describe('Manager', function() { |
14
|
|
|
before( function(done) { |
15
|
|
|
Manager.instance.init() |
16
|
|
|
.then(function () { |
17
|
|
|
|
18
|
|
|
this.fixture = { |
19
|
|
|
tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8'), |
|
|
|
|
20
|
|
|
jsonArticle: fse.readJsonSync(__dirname + '/fixtures/files/article-4.json'), |
|
|
|
|
21
|
|
|
jsonArticle1: fse.readJsonSync(__dirname + '/fixtures/data/article-1.json') |
|
|
|
|
22
|
|
|
} |
23
|
|
|
done() |
24
|
|
|
|
25
|
|
|
}.bind(this)) |
26
|
|
|
}); |
27
|
|
|
|
28
|
|
|
it('getStructureAndTemplates()', function() { |
29
|
|
|
const data = Manager.instance.getStructureAndTemplates() |
30
|
|
|
chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !') |
31
|
|
|
chai.assert.equal(data['templates'].length, 7, 'failed !') |
32
|
|
|
}); |
33
|
|
|
|
34
|
|
|
it('updateStructureAndTemplates()', function() { |
35
|
|
|
Manager.instance.updateStructureAndTemplates() |
36
|
|
|
const data = Manager.instance.getStructureAndTemplates() |
37
|
|
|
chai.assert.equal(data['templates'][0].name, 'article-each-abe', 'failed !') |
38
|
|
|
chai.assert.equal(data['templates'].length, 7, 'failed !') |
39
|
|
|
}); |
40
|
|
|
|
41
|
|
|
it('getList()', function() { |
42
|
|
|
const list = Manager.instance.getList() |
43
|
|
|
chai.assert.equal(list[0].name, 'article-1.json', 'failed !') |
44
|
|
|
chai.assert.equal(list.length, 3, 'failed !') |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
it('getListWithStatusOnFolder() status publish', function() { |
48
|
|
|
const list = Manager.instance.getListWithStatusOnFolder('publish') |
49
|
|
|
chai.assert.equal(list[0].name, 'article-1.json', 'failed !') |
50
|
|
|
chai.assert.equal(list.length, 2, 'failed !') |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
it('getListWithStatusOnFolder() status draft', function() { |
54
|
|
|
const list = Manager.instance.getListWithStatusOnFolder('draft') |
55
|
|
|
chai.assert.equal(list.length, 2, 'failed !') |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
it('getListWithStatusOnFolder() status review', function() { |
59
|
|
|
const list = Manager.instance.getListWithStatusOnFolder('review') |
60
|
|
|
chai.assert.equal(list.length, 0, 'failed !') |
61
|
|
|
}); |
62
|
|
|
|
63
|
|
|
it('getListWithStatusOnFolder() status publish /0-1', function() { |
64
|
|
|
const list = Manager.instance.getListWithStatusOnFolder('draft', '0-1') |
65
|
|
|
chai.assert.equal(list[0].name, 'article-2.json', 'failed !') |
66
|
|
|
chai.assert.equal(list.length, 1, 'failed !') |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
it('updatePostInList() with new post', function(done) { |
70
|
|
|
const len = Manager.instance.getList().length |
71
|
|
|
cmsOperations.create('article', '', 'article-4.html', {query: ''}, this.fixture.jsonArticle, false) |
72
|
|
|
.then(function(resSave) { |
73
|
|
|
const json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
74
|
|
|
const list = Manager.instance.getList() |
75
|
|
|
fse.removeSync(json) |
76
|
|
|
chai.assert.equal(list.length, len + 1, 'failed !') |
77
|
|
|
done() |
78
|
|
|
}.bind(this)); |
|
|
|
|
79
|
|
|
}); |
80
|
|
|
}); |
81
|
|
|
|